// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/SysConfigSettingApi'

import ComClass from '@api/ComQuery'
import InfoClass from '@api/base/model/SysConfigSettingReq'
import BaseClass from '@api/base/model/SysConfigSettingDto'

const EditClass = InfoClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(infoParam, TIP = '信息') {
    const DTO = CORE.grpcDTO(InfoClass, infoParam, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'sysConfigSettingQuery', DTO)
    return (resp.dto || [])[0] || {}
  },
  transInfo(obj) {
    const json = JSON.parse(obj.configValue || '{}')
    return { ...obj, ...json }
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit(one) {
    const { logo, name, address, lon, lat } = one
    const configValue = JSON.stringify({ logo, name, address, lon, lat })
    return { ...one, configValue }
  },
  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'sysConfigSettingSave', DTO)
    return CORE.grpcOK(TIP)
  },
}
